home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Shareware Grab Bag
/
Shareware Grab Bag.iso
/
007
/
strucpgm.arc
/
MANUAL
< prev
next >
Wrap
Text File
|
1984-09-14
|
96KB
|
3,763 lines
STRUCTURED PROGRAMMING LANGUAGE
STRUCTURED PROGRAMMING LANGUAGE
STRUCTURED PROGRAMMING LANGUAGE
Copyright by Dennis Baer 1983
25 Miller Road Farmingdale,N.Y. 11735
516-694-5872
This language is dedicated to you, the PROGRAMMER.
1
Structured programming language
A Structured Programming Language processor for the MS-DOS
family of computers. The instructions for running the
processor are on page 51.
The following are the statements that make up the Structured
Programming language: [ See important note on page 7. ]
Statement Page
1. BEGIN 14
2. REAL 16
3. INTEGER 18
4. STRING 19
5. REAL ARRAY 20
6. INTEGER ARRAY 21
7. STRING ARRAY 22
8. PROCEDURE 23
9. COMMENT 25
10. GO 26
11. GO TO 26
12. GOTO 26
13. ONERRGOTO 27
14. RETURN 28
15. INPUT 29
16. LINEIN 30
17. GET [I/O] 31
18. PUT [I/O] 31
19. OUTPUT 32
20. CALL 33
21. FOR 34
22. IF 35
2
Statement Page
23. END 36
24. WHILE 37
25. REPEAT 38
26. ; 39
27. WRITE *Z 10.179-10.180 *I 4-298 4-299
28. CHAIN **Z 10.13-10.14 **I 4-36
29. BEEP *Z 10.5 *I 4-28
30. BLOAD **Z 10.6-10.7 **I 4-29
31. BSAVE **Z 10.8-10.9 **I 4-32
32. CALL [EXTERNAL] *Z 10.10-10.11 *I 4-34
33. CLEAR *Z 10.18 *I 4-44
34. CLOSE **Z 10.19 **I 4-46
35. FILES **Z 10.51 **I 4-97
36. FIELD *Z 10.50 *I 4-94
37. KILL **Z 10.84 **I 4-136
38. NAME **Z 10.108 **I 4-173
39. OPEN **Z 10.115-10.121 **I 4-189,4-194
40. OUT **Z 10.123 **I 4-201
41. DOS 40
42. POKE *Z 10.127 *I 4-214
43. RESET *Z 10.146 *I 4-243
44. RESUME *Z 10.148 *I 4-245
45. RUN **Z 10.152 **I 4-251
46. STOP *Z 10.161 *I 4-270
47. WAIT *Z 10.176 *I 4-290
48. HOME 41
49. DEFSEG 42
3
Statement Page
50. ERROR *Z 10.47-10.48 *I 4-91
51. KEY *Z 10.81-10.83 *I 4-131
52. LSET *Z 10.103 *I 4-163
53. RSET *Z 10.103 *I 4-163
54. RANDOMIZE *Z 10.141 *I 4-236
55. SWAP *Z 10.164 *I 4-277
56. COLOR *Z 10.21-10.22 *I 4-49,4-54
57. DRAW *Z 10.40-10.41 *I 4-79
58. CIRCLE *Z 10.17 *I 4-41
59. GET [GRAPHICS] *Z 10.59-10.61 *I 4-108
60. PUT [GRAPHICS] *Z 10.59-10.61 *I 4-232
61. LINE *Z 10.88-10.89 *I 4-141
62. LOCATE *Z 10.97-10.98 *I 4-155
63. PRESET *Z 10.129 *I 4-228
64. PSET *Z 10.138-10.139 *I 4-228
65. PAINT *Z 10.124 *I 4-203
66. SCREEN *Z 10.155 *I 4-257
67. DATE$ *Z 10.32 *I 4-66
68. TIME$ *Z 10.168-10.169 *I 4-281
69. MID$ *Z 10.106 *I 4-167
70. WIDTH *Z 10.178 *I 4-294
71. COM(N) *Z F.8-F.10 *I 4-56
72. KEY(N) *Z F.8-F.10 *I 4-134
73. ON COM(N) *Z F.8-F.10 *I 4-176
74. ON KEY(N) *Z F.8-F.10 *I 4-182
75. NULL *Z 10.110
76. EOT 43
4
Statement Page
77. Arithmetic assignment 44
78. String assignment 45
79. Labeled statement 46
The following functions are supported in the Structured
Programming Language for MS DOS systems.
Arithmetic Function Page Page
(Z) (I)
1. ABS 10.1 4-21
2. ATN 10.3 4-25
3. CDBL 10.12 4-35
4. CINT 10.16 4-40
5. COS 10.26 4-60
6. CSNG 10.28 4-61
7. EXP 10.49 4-93
8. FIX 10.52 4-99
9. INT 10.80 4-130
10. LOG 10.100 4-159
11. RND 10.151 4-249
12. SGN 10.156 4-260
13. SIN 10.157 4-261
14. SQR 10.160 4-267
15. TAN 10.167 4-280
String function Page Page
(Z) (I)
1. ASC 10.2 4-24
2. CHR$ 10.15 4-38
3. CVI 10.30 4-63
4. CVS 10.30 4-63
5
String Function Page Page
(Z) (I)
5. CVD 10.30 4-63
6. EOF 10.44 4-86
7. FRE 10.57 4-104
8. HEX$ 10.64 4-115
9. INPUT$ 10.78 4-127
10. INSTR 10.79 4-129
11. LEFT$ 10.85 4-137
12. LEN 10.86 4-138
13. LOC 10.96 4-153
14. LOF 10.99 4-158
15. MID$ 10.105 4-167
16. MKI$ 10.107 4-170
17. MKS$ 10.107 4-170
18. MKD$ 10.107 4-170
19. OCT$ 10.111 4-175
20. RIGHT$ 10.150 4-248
21. SPACE$ 10.158 4-265
22. STR$ 10.162 4-272
23. STRING$ 10.163 4-276
24. VAL 10.172 4-285
Special Functions Page Page
(Z) (I)
1. CSRLIN 10.29 4-62
2. FRE 10.57 4-104
3. INP 10.71 4-121
4. LPOS 10.101 4-160
5. PEEK 10.125 4-205
6. POINT 10.126 4-213
6
Special Functions Page Page
(Z) (I)
7. POS 10.128 4-215
8. SCREEN 10.154 4-255
9. SPC 10.159 4-266
10. TAB 10.166 4-279
11. VARPTR 10.173 4-286,4-288
12. WIDTH 10.178 4-294
Special Variables
1. ERR 10.46 4-89
2. ERL 10.46 4-89
3. INKEY$ 10.70 4-119
Additional categories Page
STATEMENT FORMATS 9
ARITHMETIC OPERATORS 47
STRING OPERATORS 47
LOGICAL OPERATORS 47
COMPARISON OPERATORS 47
IMPLEMENTATION RESTRICTIONS 48
REAL,INTEGER,STRING CONSTANTS 49
APPLICATION NOTES 50
RUNNING THE PROCESSOR 51
ERROR MESSAGES 52
INDEX 56
Note: *Z *I means refer to page in computer manufacturers
BASIC manual. **Z **I means refer to page in computer
manufacturers BASIC manual but command is slightly different.
parentheses must be placed after the key word and before the
semicolon. (Z=Zenith,I=IBM) See each statement format from pages
8 through 13. The statement must have variable names that conform
to Structured Programming Language standards. If you don't see
page references for your computer then consult your BASIC manual.
7
Programs written in the Structured Programming Language are
kept in an ASCII text file. Any text editor that can create an
ASCII text file for MS DOS can be used to write Structured
Programming Language programs. It is a free format block and
procedure oriented language that runs in the MS DOS environment.
Each computer's implementation of a computer language has its own
unique characteristics. In this implementation of the Structured
Programming Language, the processor uses the text file of
Structured Programming Language statements as input and
translates this program to BASIC in an ASCII text file for the
particular MS DOS system. The text file can be run by the BASIC
interpreter or be compiled by the BASIC compiler after it is
loaded into the interpreter workspace and then saved in ASCII
format on the users disk drive. This manual is intended to be a
reference manual for the MS DOS version of the Structured
Programming Language and is not meant to be a tutorial. To get an
idea of procedure oriented and block structured languages, you
can read books on the ALGOL and PASCAL languages.
8
The following are the statement formats for the Structured
Programming Language.
1. BEGIN
2. REAL <variable> {,<variable>,..........,<variable>};
3. INTEGER <variable> {,<variable>,..........,<variable>};
4. STRING <variable> {,<variable>,..........,<variable>};
5. REAL ARRAY <array variable>(<bounds>) {,<array variable>
(<bounds>),..........};
6. INTEGER ARRAY <array variable>(<bounds>) {,<array variable>
(<bounds>),..........};
7. STRING ARRAY <array variable>(<bounds>) {,<array variable>
(<bounds>),..........};
8. PROCEDURE <procedure name> { (<parameter list>) };
BEGIN
<statements>
END
9. COMMENT <text>; [Note: <text> should not contain ' char.]
10. GO <label>;
11. GO TO <label>;
12. GOTO <label>;
13. ONERRGOTO <label>;
14. RETURN {<label>};
15. INPUT( {@} {<prompt string>{@|,}} <variable list> );
15a. INPUT( #<file number>,<variable list> );
15b. LINEIN( {@} {<prompt string>{@|,}} <string variable>);
15c. LINEIN( #<file number>,<string variable>);
16. GET #<file number> {,<record number>};
17. PUT #<file number> {,<record number>};
9
18. OUTPUT( {#<file number>,} {USING <string expression>@}
{<output expression list>} );
19. {CALL} <procedure name> {( <argument list> )};
20. FOR <scalar arithmetic variable> := <start arith. expr.>
STEP <increment arithmetic expression>
UNTIL <limit arithmetic expression>
DO BEGIN
<statements>
END
21. IF <logical expression> THEN <statement>
{ ELSE <statement> }
Note: In each of the clauses THEN,ELSE the <statement>
can be replaced with BEGIN <statements> END
The single statement may not be an IF,FOR,REPEAT,REAL,
INTEGER,STRING,PROCEDURE,ON, or WHILE statement. You
must place it between BEGIN and END statements.
22. END
23. WHILE <logical expression> DO
BEGIN
<statements>
END
24. REPEAT <statements>
UNTIL <logical expression>;
25. ;
26. WRITE {#<file number>,} {<expression list>};
27. CHAIN( <file name> );
28. BEEP;
29. BLOAD( <file name> {,<offset>} );
10
30. BSAVE( <file name>,<offset>,<length> );
Note:The offset is added to the current segment address
which gives the address.
31. CALL <variable> {( <argument list> )};
Note:<variable> is an INTEGER variable that has the same
name as a global program name as in PASCAL,ASSEMBLER, or
FORTRAN (by MICROSOFT)
32. CLEAR {{,<highest location>} {,<stack space>}};
33. CLOSE( {#} <file number> {,{#} <file number>,..........} );
34. FILES( { <files> } );
35. FIELD # <file number>,<field width> AS <string variable>,
{ <field width> AS <string variable>,.......... };
36. KILL( <files> );
37. NAME( <file name> AS <new file name> );
38. OPEN( <mode>,{#} <file number>,<file name> {,<record len.>} );
Note:The <mode> in 38. is 'O','I',or 'R'
38a. OPEN( <file name> { FOR <mode> } AS {#} <file number>
{ LEN = <record length> } );
Note:The <mode> in 38a. is INPUT,OUTPUT,or APPEND. RANDOM
is assumed if mode is left out.
38b. OPEN( 'COM1:<speed>,<parity>,<data>,<stop>' AS <file no.> );
39. OUT( <port number>,<data> );
40. DOS;
Note:This statement brings the user back to MS DOS.
41. POKE <machine location offset>,<data>;
42. RESET;
43. RESUME { <label> };
44. RUN( <file name> );
11
45. STOP;
46. WAIT <port address>,<integer expr.>,<integer expr.>;
47. HOME; Note:This statement clears the screen.
48. DEFSEG := <expression>;
49. ERROR <integer expression>;
50. KEY <key number>,<string expression>;
50a. KEY LIST;
50b. KEY ON;
50c. KEY OFF;
51. LSET <string variable> := <string expression>;
52. RSET <string variable> := <string expression>;
53. RANDOMIZE <arithmetic expression>;
54. SWAP <variable>,<variable>;
55. COLOR { <foreground> } {,<background> };
56. DRAW <string expression>;
57. CIRCLE (<x center>,<y center>),<radius> {,<color {,<start>
,<end> {,<aspect ratio>}}};
58. GET (<x1>,<y1>)-(<x2>,<y2>),<array name>;
59. PUT (<x1>,<y1>),<array name> {,<action verb> };
Note: <action verb> is AND,OR,XOR,PSET,or PRESET
60. LINE (<x1>,<y1>)-(<x2>,<y2>) {,{<color>} {,B {F}};
Note:Lower case letters b,f can be used instead of B,F
61. LOCATE {<row>},{<column>} {,{<cursor>}};
62. PRESET (<x>,<y>) {,<color>};
62a. PRESET STEP (<x offset>,<y offset>) {,<color>};
63. PSET (<x>,<y>) {,<color>};
63a. PSET STEP (<x offset>,<y offset>) {,<color>};
64. PAINT (<x start>,<y start>) {,<paint color> {,<border color>}};
12
65. SCREEN {<graphics mode>,} {<reverse video>};
66. DATE$ := <date string expression>;
67. TIME$ := <time string expression>;
68. MID$(<string expr. 1>,<integer expr. 1>{,<integer expr. 2>})
:= <string expression 2>;
69. WIDTH <integer expression>;
70. COM( <arithmetic expression> ) ON
OFF ;
STOP
71. KEY( <arithmetic expression> ) ON
OFF ;
STOP
72. ON COM( <arithmetic expression> ) THEN CALL <procedure name> ;
73. ON KEY( <arithmetic expression> ) THEN CALL <procedure name> ;
Note: For statements 72. and 73. the <procedure name> represents
a procedure without arguments.
74. NULL <integer expression>;
75. <space> EOT <space>
Note:This must be on the last line of the file.
76. <arithmetic variable> := <arithmetic expression>;
77. <string variable> := <string expression>;
78. <label>:.....:<label>:<executable statement>;
Anything in between { } is optional.
Anything between < > means a description of the value and that
the < > are not part of the statement.
Repetition symbol ......... means that an item can be repeated.
13
BEGIN
Format: BEGIN
The BEGIN statement is used to define the start of a
Structured Programming Language program or a start of a new block
in a program. It tells the Structured Programming Language
processor that a new logical unit of declarations of variables
and executable instructions starts. It also creates a new level
of variable storage. The first BEGIN statement does both, defines
the start of a program and the start of a new block. An example
of BEGIN usage.
BEGIN
REAL x,y,fnc;
INPUT(x,y);
fnc:=x*y; OUTPUT(fnc);
END
In the above example, the reserved word BEGIN defines the
start of the program and tells the Structured Programming
Language processor that a new block has started. Reserved words
should not be used as variable names, label names,
procedures,etc. If you do then they will conflict with the
meaning of these words and will not be taken as variables.
Reserved words are Structured Programming Language statement
names, and the various mathematical, string, file functions and
operators. The user shall find reference to these reserved words
in the table of contents. Another example of the usage of BEGIN.
BEGIN
REAL X,Y,FNC;
ask:INPUT(X,Y); FNC:=X*Y;
IF FNC<0 THEN
BEGIN
OUTPUT('The value of FNC is less than zero');
GO ask;
END
END
In the above example, the first BEGIN statement defines the
start of the program and the first level of storage and
executable statements. The second BEGIN statement defines a new
block, but in this case the block will only be entered if the
condition of the clause of the IF statement is true. That is IF
FNC < 0. This second BEGIN block can contain declaration
statements if the user chooses to put them in there. Any BEGIN
block can contain both declaration and executable statements. The
rule however is that the declaration statements must precede the
executable statements. The END statement defines an end to a
logical block of statements and declarations of variables. These
variables when declared in a block will be known in that block
and any block declared inside that block. If the condition FNC <
0 is false, then execution will skip the second BEGIN
14
statement, the OUTPUT statement,the GO statement and the END
statement. Execution then continues with the statement after that
END statement, which is the final END statement in this case.
When execution reaches the final END statement, the program ends
and control goes back to the system. A third example of BEGIN.
BEGIN
REAL a,h,c;
INTEGER i,j,k;
a:=5; h:=25;
Insideblock:
BEGIN
REAL a1,b1,function;
function:=(a+h)^2.; OUTPUT(function); c:=function;
END
IF c>500 THEN
BEGIN
OUTPUT('(a+h)^2. is greater than 500');
END
ELSE
BEGIN
OUTPUT('(a+h)^2. is less than or equal to 500');
END
IF c>800 THEN GO TO Insideblock;
END
In this above example there is the main BEGIN END block that
contains the entire program. In the main block the variables
a,h,c,i,j,k are declared. The block labeled Insideblock is
an inner block that computes the value function and c. A third
block is a THEN clause of the IF statement and is only executed
if the logical expression of the IF statement is true. That is if
c>500. The fourth block is executed only if the logical
expression of the IF statement is false. Now notice the second IF
statement, if c>800 then execution will go to the BEGIN block
labeled Insideblock. In this program there are three blocks
inside the first block, which is the main program.
15
REAL
Format: REAL <variable> {,<variable>,..........,<variable>};
The REAL statement is a nonexecutable declaration statement
which informs the Structured Programming Language processor that
the variables declared are REAL scalar variables. They contain
single precision floating point numbers. The identifier is the
actual name of the variable that is declared and referenced in a
Structured Programming Language program. An identifier is a name
of up to 40 characters which begins with an uppercase or
lowercase alphabetic character. Subsequent characters can be
upper or lower case letters, numbers, dollar sign, or an
underscore. An example of the REAL statement.
BEGIN
REAL X,Y,Z,FUNCTION;
INTEGER percentile;
REAL a1,a2,a3;
X:=Y+Z; FUNCTION:=SQR(X^2.+Y^2.);
BEGIN
a1:=5; a2:=10; a3:=a1^a2; OUTPUT('a3 is:'@ a3);
END
END
The above example is a small program. The first REAL
statement declares that X,Y,Z,FUNCTION are REAL scalar variables
in that block and are known in any block nested in that block
unless the name is reused in a declaration statement in the
nested block. Names declared in a BEGIN block are not known
outside the block. The second REAL statement declares that
a1,a2,a3 are real variables in that block. Note that the
variables a1,a2,a3 referenced in the inside BEGIN block are
actually declared in the outer block,which incidently is the main
program block. Another example of the REAL statement.
BEGIN
REAL a,h;
a:=1; h:=2;
BEGIN
REAL a,c;
a:=3; c:=4; OUTPUT('The product of a and h is:'@ a*h);
IF a+h<4 THEN
BEGIN
REAL c,d;
c:=5; d:=6; OUTPUT('The sum of c and d is:'@ c+d);
END
END
END
In the above example a and h are declared as REAL scalar
variables in the outermost program block. The second REAL
statement declares a and c to be REAL scalar variables. It is
important to note that at the first OUTPUT statement that the
reference to the REAL variable a is the variable a that was
16
declared in the second BEGIN block that is nested in the main
program BEGIN block. a was set to 3 in this inner block and this
variable a is much different from the variable a in the outer
BEGIN block. Each variable a has a location allocated to it to
store one single precision floating point number. However the
REAL variable h referenced in the inner block is the same
variable h that is declared in the outer block because the rule
is that a nested BEGIN block knows all variables outside of it,
except if the same variable name is used in a declaration
statement. But h is not redeclared, so it is known. c is known
because it is declared in the inner second block. Now note the
third BEGIN block. It is only executed if the logical statement
a+h<4 is true. This third block has a REAL statement that
declares c and d to be REAL scalar variables. At the OUTPUT
statement in this third block c is the variable c declared in
this block and d is also the one that is declared in this block.
In addition, variable a if it were to be referenced would be the
variable a declared in the second block and h would be the
variable declared in the first outermost program block. So you
see that depending on what variables are declared and where they
are referenced, the actual storage can vary. In summation the
REAL statement sets up storage that is known for the block and
for any block nested inside of it, except those blocks that
redeclare that name. The storage for the variable is static and
is not lost if you exit the block in which it is declared.
Variable names cannot be any of the various key words that are
defined in the Structured Programming Language. See the table of
contents for the reserved words. They include the statement names
and mathematical,string,and file functions. A REAL variable may
contain a number ranging from 10^-38 to 10^38 or -10^38 to -10^-
38. with 9 digits of precision.
17
INTEGER
Format: INTEGER <variable>{,<variable>,..........,<variable>};
The INTEGER statement is a nonexecutable declaration
statement that informs the Structured Programming Language
processor that the variables named are scalar INTEGER variables.
For an explanation of what an identifier is, see the REAL
statement section. An example.
BEGIN
INTEGER i,j,k;
i:=1; j:=2; k:=3;
BEGIN
INTEGER i,j,m;
m:=i+j+k; OUTPUT(m,i,j,k);
END
END
The first INTEGER statement declares i,j,k as scalar INTEGER
variables in the outermost program block. The i,j that are
declared here will not be known by the second block which is
nested in the first block. The variable k is known in the second
block as an INTEGER scalar variable. The second INTEGER statement
declares that i,j,m are scalar INTEGER variables. Variable m is
not known in the outer block, and the variables i and j declared
in the inner block are different from the variables i and j
declared in the outer block. INTEGER variables can hold a number
between -32767 and 32767. The rule, that has been mentioned in
the REAL section, about what variables are known in what block is
the rule of SCOPE of VARIABLES.
18
STRING
Format: STRING <variable> {,<variable>,..........,<variable>};
The STRING statement is a nonexecutable declaration
statement that informs the Structured Programming Language
processor that the named variables are to be scalar STRING
variables. For an explanation of identifiers and the rule of
SCOPE of VARIABLES see the sections of REAL and INTEGER
variables. An example.
BEGIN
REAL x,y;
STRING Name,Address,Phone;
INPUT(Name,Address,Phone);
OUTPUT(MID$(Name,1,INSTR(Name,' ')),Phone);
END
Name,Address,Phone are declared to be STRING scalar
variables. A STRING scalar variable can hold up to 32767
characters, if you will be using the translated BASIC program to
be compiled with a compiler. If the translated program will run
as an interpreted program then the maximum amount of characters
that a STRING can hold is 255. The least amount of characters is
0 which represents the NULL string. The amount of characters that
a STRING holds varies depending on the length of the string
expression at the time of assignment of the variable.
19
REAL ARRAY
Format: REAL ARRAY <array variable>(<bounds>)
{,<array variable> (<bounds>),..........};
The REAL ARRAY statement is a nonexecutable declaration
statement that informs the Structured Programming Language
processor that the named variables are REAL ARRAY variables.
Static storage is set aside for these arrays. See the section on
REAL variables for an explanation of identifiers and SCOPE of
VARIABLES. An example.
BEGIN
INTEGER intg1,intg2,intg3,count;
REAL zz,aa,bb;
REAL ARRAY y(100,100),x(5,5);
REAL ARRAY Z(4,4,4);
FOR intg1:=1 STEP 1 UNTIL 100 DO
BEGIN
FOR intg2:=1 STEP 1 UNTIL 100 DO
BEGIN
y(intg1,intg2):=0;
END
END
END
In this program three arrays are declared in the block. They
are: y(100,100) x(5,5) and Z(4,4,4). ARRAY bounds in a
ARRAY declaration statement must be unsigned integer constants.
20
INTEGER ARRAY
Format: INTEGER ARRAY <array variable>(<bounds>)
{,<array variable>(<bounds>),..........};
The INTEGER ARRAY statement is a nonexecutable declaration
statement that informs the Structured Programming Language
processor that the named variables are INTEGER ARRAY variables.
Static storage is set up for each INTEGER ARRAY variable. See the
section on REAL variables for details on identifiers and SCOPE OF
VARIABLES. An example.
BEGIN
INTEGER ARRAY N(15,5),PIX(20,3);
INTEGER i,j,min;
min:=-32760;
FOR i:=1 STEP 1 UNTIL 15 DO
BEGIN
FOR j:=1 STEP 1 UNTIL 5 DO
BEGIN
INPUT(N(i,j)); IF N(i,j)<min THEN min:=N(i,j);
END
END
OUTPUT('minimum value is:' @ min);
END
In the above example INTEGER ARRAY variables N(15,5) and
PIX(20,3) are declared. ARRAY bounds in an ARRAY declaration
statement must be unsigned integer constants.
21
STRING ARRAY
Format: STRING ARRAY <array variable>(<bounds>)
{,<array variable>(<bounds>),..........};
The STRING ARRAY statement is a nonexecutable declaration
statement that informs the Structured Programming Language
processor that the named variables are STRING ARRAY variables.
Static storage is set up for the STRING ARRAY variable. See the
section on REAL variables for details of identifiers and SCOPE of
VARIABLES. An example.
BEGIN
STRING ARRAY NAMES_of_STATES(50);
INTEGER i;
FOR i:=1 STEP 1 UNTIL 50 DO
BEGIN
INPUT('Name of state:' @ NAMES_of_STATES(i));
IF NAMES_of_STATES(i)='New York' THEN
BEGIN
OUTPUT('Thats the one:' @ NAMES_of_STATES(i));
OUTPUT('after ' @ i @ ' tries');
STOP;
END
END
END
In the above example the STRING ARRAY variable
NAMES_of_STATES(50) is declared. ARRAY bounds in an ARRAY
declaration statement must be unsigned integer constants.
22
PROCEDURE
Format: PROCEDURE <procedure name> { (<parameter list>) };
BEGIN
<statements>
END
The PROCEDURE statement sets up a group of statements and
associates them with a single name. It informs the Structured
Programming Language processor of this declaration. It is
technically a nonexecutable declaration and must be placed before
executable statements. The statements between its BEGIN and END
block are nonexecutable and executable. The nonexecutable
statements are processed by the Structured Programming Language
processor. The executable statements are also processed but are
not executed until the PROCEDURE is called either by a CALL
statement or by referencing it by its name. An example.
BEGIN
REAL Aa,Bb,Cc; { Declare parameters. }
REAL Root_1,Root_2; { Declare Outputs of PROCEDURE. }
PROCEDURE Quadratic_roots(Aa,Bb,Cc); { Parameter references. }
BEGIN
REAL Factor;
Factor:=Bb*Bb-4.*Aa*Cc;
IF Factor<0 THEN
BEGIN
Root_1:=10^(-10); Root_2:=10^(-10);
RETURN;
END
Root_1:=(-Bb+SQR(Factor))/(2.*Aa);
Root_2:=(-Bb-SQR(Factor))/(2.*Aa);
END { Note: this END statement will execute a RETURN. }
REAL Constant_A,Constant_B,Constant_C;
Ask_for_quadratic_constants:
INPUT('Enter A,B,C:' @ Constant_A,Constant_B,Constant_C);
Quadratic_roots(Constant_A,Constant_B,Constant_C); {Arguments}
OUTPUT(); OUTPUT(Root_1,Root_2); OUTPUT();
GO Ask_for_quadratic_constants;
END
The above example defines a PROCEDURE Quadratic_roots which
has three arguments. This PROCEDURE is used to compute the roots
of a quadratic equation.
Note:Parameters in the PROCEDURE declaration can be
REAL,INTEGER, or STRING scalar variables. These parameters should
be first declared in a block containing the PROCEDURE or outside
it. For documentation purposes they can be declared immediately
before the PROCEDURE. The variable should then be named in the
parameter list for the PROCEDURE. If the variable is not
declared, then the parameter will be assumed to be a STRING
scalar. Corresponding arguments in PROCEDURE calls must match the
type of the parameter. Arguments are passed by value to
corresponding parameters. Signed INTEGER constants or positive
23
fractional numbers less than 1 may be passed to a REAL or
INTEGER. STRING constants can be passed to a STRING.
REAL,INTEGER, and STRING scalar variables can be arguments to a
PROCEDURE but they must match by type exactly. Expressions for
arguments are not allowed.
Note:Since the PROCEDURE statement is a declaration
statement, control of the program passes around the PROCEDURE and
in the above example the labelled INPUT statement is executed
first.
Another example.
BEGIN
STRING Name,Address,Phone,RESULT;
STRING A,H,C; { Declare parameters for the PROCEDURE. }
PROCEDURE FORMAT(A,H,C);
BEGIN
INTEGER I;
RESULT:='';
FOR I:=1 STEP 1 UNTIL 20 DO
BEGIN
IF I>LEN(A) THEN RESULT:=RESULT+' ';
ELSE RESULT:=RESULT+MID$(A,I,1);
END
FOR I:=21 STEP 1 UNTIL 40 DO
BEGIN
IF (I-20)>LEN(H) THEN RESULT:=RESULT+' ';
ELSE RESULT:=RESULT+MID$(H,I-20,1);
END
FOR I:=41 STEP 1 UNTIL 60 DO
BEGIN
IF (I-40)>LEN(C) THEN RESULT:=RESULT+' ';
ELSE RESULT:=RESULT+MID$(C,I-40,1);
END
END
Name := 'John Smith' ; Address := '85 Broadway' ;
Phone := '203-555-2035' ;
FORMAT(Name,Address,Phone); { Call to FORMAT PROCEDURE }
OUTPUT(RESULT);
END
The above example shows a program which has a PROCEDURE
FORMAT which combines the first 20 characters of each of the
three arguments Name,Address,Phone leaving the value in RESULT.
Note:A PROCEDURE may access globally declared variables. For
documentation purposes these variables can be declared just
before the PROCEDURE that uses them.
Note:PROCEDURE's can be called recursively and the RETURN
addresses are saved on the STACK of the runtime system but the
user must save any arguments and variables used in the PROCEDURE
for each level of invoking a PROCEDURE.
24
COMMENT , { }
Format: COMMENT <text>; [Note: <text> should not contain ' ]
or { <text> }
The COMMENT statement is a statement used in a Structured
Programming Language program to insert comments in the program
for documentation purposes. This statement is nonexecutable, but
can be placed almost anywhere in a program. An example.
BEGIN
REAL x,y,z,sumsquare;
OUTPUT('Input x,y,z'); INPUT(x, {anywhere} y,z);
sumsquare := x^2. + y^2. + z^2. ;
COMMENT
sumsquare is equal to the sum of the squares of x,y and z;
OUTPUT('The sum of the squares of');
{ This is another example of a comment and you can embed
a quote ' in the text ,and this comment can appear any
where in the program. The end of the comment is this }
OUTPUT(x @' PLUS ' @ y @' PLUS ' @ z @' IS ' @ sumsquare);
END
The above example shows the COMMENT statement and the text
between COMMENT and the semicolon. It is important to note that
the single quote ' should not be used in the text of a COMMENT
statement. The second method of making a comment is by enclosing
any text between { and } characters. This second type of comment
may have a single quote embedded,and can appear anywhere.
25
GO , GO TO , GOTO
Format: GO <label>; or GO TO <label>; or GOTO <label>;
These statements in the Structured Programming Language
are used to transfer control of the computer to a labeled
Structured Programming Language statement. An example.
BEGIN
INTEGER a,h,c;
a:=-1;
compute: a:=a+1;
INPUT(h);
IF h<0 THEN GO compute;
ELSE OUTPUT(a,' numbers < 0');
END
The above example shows the use of the GO TO statement.
Control passes back to the statement labeled compute if the
variable h < 0. This example counts the number of values input
that are less than zero. Once h >= 0 as entered for input then
control passes to the OUTPUT statement and the program continues
on.
26
ONERRGOTO
Format: ONERRGOTO <label>;
The ONERRGOTO statement allows the user to trap errors and
transfer control of the computer to a labeled statement. See your
BASIC manual for the ERROR codes for your system. You can also
refer to your Disk Operating System manual. An example.
BEGIN
REAL A,H,C;
STRING D,E,F;
OPEN('I',#1,'DATA.FIL');
ONERRGOTO end_of_file;
OUTPUT();
read:LINEIN(#1,D); COMMENT read in a line of data ;
OUTPUT(D); COMMENT output the line to the screen ;
GO read;
end_of_file:RESUME end_of_file1;
end_of_file1:CLOSE(); STOP;
END
The above example shows a use of the ONERRGOTO statement to
trap execution of a program when an end of file is encountered
for a sequential disk file. When the end of file is reached
control is transferred to the labeled statement end_of_file. The
RESUME statement is executed, as required and the program closes
all files and stops.
27
RETURN
Format: RETURN;
The RETURN statement is a statement that ends execution of a
PROCEDURE and returns control to the statement following the call
to the PROCEDURE. There is also a form of this statement that
allows transfer to a labeled statement. An example.
BEGIN
REAL a,h,c;
REAL d,e;
PROCEDURE add(d,e);
BEGIN
c:=d+e;
IF c=0 THEN RETURN zero;
RETURN;
END
zero:INPUT('enter a,h'@ a,h);
add(a,h);
END
The above example shows the two forms of RETURN statement.
If c=0 then the program control goes to the statement labeled
zero. Otherwise control goes normally to the statement following
the call to PROCEDURE add, which is the final END statement of
the program. Execution ends at this point.
Note:The END statement of the PROCEDURE declaration is
equivalent to a RETURN statement. RETURN is made to the statement
after the CALL to the PROCEDURE.
28
INPUT
Format: INPUT( {@} {<prompt string>{@|,}} <variable list> );
INPUT( #<file number>,<variable list> );
The INPUT statement in the Structured Programming Language
is very similar to the INPUT statement in the BASIC language for
your computer. There are some differences. The INPUT statement is
used to get information into storage from an external device into
your Structured Programming Language program. The Structured
Programming Language INPUT statement differs from the BASIC
statement in that the @ (at sign) is used instead of the ;
(semicolon) as a separator. Variable names must conform to
Structured Programming Language standards. The INPUT statement
must have parentheses around the INPUT list. See the format for
the INPUT statement in the statement format section on page 9.
Additional information can be found in your BASIC users manual.
Pages
Zenith BASIC 6.1-6.30 and 10.72-10.77
IBM BASICA 3-33,3-38,3-44,4-122,4-125
An example.
BEGIN
INTEGER A,I;
REAL H;
STRING C;
INTEGER ARRAY SPOTS(10);
INPUT('Enter values for A,H,C' @ A,H,C);
FOR I:=1 STEP 1 UNTIL 10 DO
BEGIN
OUTPUT('Enter value of SPOTS(' @ STR$(I) @ ') :' @);
INPUT(SPOTS(I));
END
OPEN('I',#1,'INFILE.DAT');
READIT:IF EOF(1) THEN
BEGIN
CLOSE(#1); STOP;
END
INPUT(#1,C); OUTPUT(C);
GO READIT;
END
The above example shows the use of the INPUT statement. The
first two INPUT statements are used to get input from the
keyboard and the third is to get input from a disk file named
INFILE.DAT .
29
LINEIN
Format: LINEIN( {@} {<prompt string>{@|,}} <string variable>);
LINEIN( #<file number>,<string variable>);
The LINEIN statement in the Structured Programming Language
is very similar to the LINE INPUT statement in the BASIC language
for your computer. There are some differences. The LINEIN
statement is used to get information into storage from an
external device into your Structured Programming Language
program. The Structured Programming Language LINEIN statement
differs from the BASIC statement in that the @ (at sign) is used
instead of the ; (semicolon) as a separator. Variable names must
conform to Structured Programming Language standards. The LINEIN
statement must have parentheses around the LINEIN input list.
See the format for the LINEIN statement in the statement format
section on page 9. Additional information can be found in your
BASIC users manual.
Pages
Zenith BASIC 6.1-6.30 and 10.90-10.91
IBM BASICA 3-33,3-38,3-44,4-144,4-145
An example.
BEGIN
INTEGER A,I;
REAL H;
STRING C;
OPEN('I',#1,'INFILE.DAT');
READIT:IF EOF(1) THEN
BEGIN
CLOSE(#1); STOP;
END
LINEIN(#1,C); OUTPUT(C);
GO READIT;
END
The above example shows the use of the LINEIN statement. The
LINEIN statement is used to get a line of input from a disk file
named INFILE.DAT.
30
GET , PUT
Format: GET #<file number> {,<record number>};
PUT #<file number> {,<record number>};
The GET and PUT statements in the Structured Programming
Language are used to read and write records from a disk file in
the random access mode. See the statement formats for these
statements on page 9 of this manual. Since these statements are
the same as the BASIC statements for your machine, except that
variables must conform to Structured Programming Language
variable standards, additional information can be found in your
BASIC users manual.
Page
Zenith BASIC 6.16-6.29 and 10.58 and 10.140
IBM BASICA 3-33,3-38,3-44,4-106,4-230
31
OUTPUT
Format: OUTPUT( {#<file number>,} {USING <string expression>@}
{<output expression list>} );
The OUTPUT statement in the Structured Programming Language
is very similar to the PRINT statement in the BASIC language for
your computer. There are some differences. The OUTPUT statement
is used to send information from storage to an external device
from your Structured Programming Language program. The Structured
Programming Language OUTPUT statement differs from the BASIC
statement in that the @ (at sign) is used instead of the ;
(semicolon) as a separator. Variable names must conform to
Structured Programming Language standards. The OUTPUT statement
must have parentheses around the OUTPUT list. See the format for
the OUTPUT statement in the statement format section on page 10.
Additional information can be found in your BASIC users manual.
For each reference of the word PRINT the word OUTPUT shall apply
in the Structured Programming Language.
Pages
Zenith BASIC 6.1-6.30 and 10.130-10.137
IBM BASICA 3-33,3-38,3-44,4-216,4-219,4-225
An example.
BEGIN
INTEGER i; STRING format;
format:='##.#####';
OPEN('OUTFIL.DAT' FOR OUTPUT AS #1);
FOR i:=1 STEP 1 UNTIL 10 DO
BEGIN
OUTPUT( USING format
@ 'The square root of ' @ i @ ' is ' @ SQR(i) );
OUTPUT(#1,USING format
@ 'The square root of ' @ i @ ' is ' @ SQR(i) );
END
END
In the above example a disk file is opened and square roots
are computed and output to the screen and the disk file
OUTFIL.DAT. The USING feature is used to set a format for output.
32
CALL
Format: {CALL} <procedure name> {( <argument list> )};
The CALL statement is used to call a Structured Programming
Language PROCEDURE. The user can call a PROCEDURE by name as well
without CALL. In order for a CALL to be legal the PROCEDURE must
be known. That is, it must be declared in the same BEGIN block as
the call or declared in a BEGIN block outside of the BEGIN block
where the PROCEDURE is referenced. It cannot be declared in a
BEGIN block nested in the current block where the call is made.
An example.
BEGIN
INTEGER A,H,C;
INTEGER IA,IB;
PROCEDURE SUM(IA,IB);
BEGIN
C:=IA+IB;
END
A:=5; H:=6; SUM(A,H); OUTPUT(C);
CALL SUM(10,30); OUTPUT(C);
END
In this example, are the two ways the user can call a
procedure, by either just mentioning its name and arguments, or
by CALL and then its name and arguments.
Note:A PROCEDURE may be called with arguments that are
globally declared variables. For documentation purposes these
variables can be declared just before the PROCEDURE that uses
them.
Note:PROCEDURE's can be called recursively and the RETURN
addresses are saved on the STACK of the runtime system but the
user must save any arguments and veriables used in the PROCEDURE
for each level of invoking a PROCEDURE. An example:
BEGIN
INTEGER N, {Argument.} {Global variable.}
Factorial_result; {Result.} {Global variable.}
PROCEDURE Factorial;
BEGIN
IF N=1 THEN
BEGIN
Factorial_result := 1; RETURN;
END
ELSE
BEGIN
N := N-1; Factorial; N := N+1;
Factorial_result := N * Factorial_result; RETURN;
END
END
N := 5; Factorial; OUTPUT(Factorial_result);
END
33
FOR
Format: FOR <scalar arithmetic variable> := <start arith. expr.>
STEP <increment arithmetic expression>
UNTIL <limit arithmetic expression>
DO BEGIN
<statements>
END
The FOR statement allows the user to do repetitve processes
and use a variable that has a varying value for each repetition.
An example.
BEGIN
REAL ARRAY x(100),y(100);
REAL xvalue,yvalue;
INTEGER i;
i:=1;
FOR xvalue:=.01 STEP .01 UNTIL 1. DO
BEGIN
IF i<=100 THEN
BEGIN
x(i):=xvalue; yvalue:=SIN(xvalue)*EXP(xvalue);
y(i):=yvalue; OUTPUT(x(i),y(i));
END
i:=i+1;
END
END
The above example shows a FOR loop that computes 100 x,y
pairs where the x's vary from .01 to 1 and the corresponding y
value is SIN(x)*EXP(x). This loop will be executed 100 times when
xvalue becomes greater than 1. The arithmetic expression after
the := is the initial value. The arithmetic expression after STEP
is the increment or decrement and finally the arithmetic
expression after UNTIL is the limit. The loop is executed only if
the initial value has not reached the limit, depending on the
magnitude of the STEP value.
34
IF
Format: IF <logical expression> THEN <statement>
{ ELSE <statement> }
Note: In each of the clauses THEN,ELSE the <statement>
can be replaced with the BEGIN <statements> END
The single statement may not be an IF,FOR,REPEAT,REAL,
INTEGER,STRING,PROCEDURE,ON, or WHILE statement. You
must place it between BEGIN and END statements.
The IF statement is used to test logical conditions and
depending on that logical condition the program can take certain
action. If the logical condition is true, actions are taken on
the THEN path or if it is false, actions are taken on the
optional ELSE path or action passes to the next statement after
the extent of the THEN clause. An example.
BEGIN
INTEGER i,j,k;
FOR i:=10 STEP -1 UNTIL 1 DO
BEGIN
INPUT('Enter number:' @ j);
IF j<0 THEN
BEGIN
OUTPUT('The number is less than zero');
k:=k+1;
END
ELSE OUTPUT('The number is greater than equal to zero');
END
OUTPUT('There were ' @ k @ ' negative numbers input');
END
The above example has the user enter 10 numbers and tells
the user if the number was greater than zero or not. It also
computes the total of numbers that were less than zero. The IF
statement tests if j<0. If j<0 the THEN clause is executed and
the message is output that the number is negative or zero, and
the number of negative numbers is incremented by 1. Otherwise the
ELSE clause is executed and the message that the number is
greater than or equal to zero is output.
35
END
Format: END
The END statement defines the end of a BEGIN block for a
normal BEGIN block, for a PROCEDURE BEGIN block, for a FOR loop
BEGIN block, for a THEN clause BEGIN block, for an ELSE clause
BEGIN block or the program BEGIN block. An example.
BEGIN
REAL SQUARE,ROUND;
INTEGER A,H,C;
SQUARE:=2; ROUND:=1;
FOR A:=30 STEP 2 UNTIL 50 DO
BEGIN
SQUARE:=ROUND+A*SQUARE;
END
OUTPUT(SQUARE);
END
In the above example the first END statement ends the FOR
loop BEGIN block. The second END ends the program BEGIN block.
36
WHILE
Format: WHILE <logical expression> DO
BEGIN
<statements>
END
The WHILE statement is used to repeat execution of a set of
statements while a certain logical condition is true. An example.
BEGIN
REAL x;
x:=5;
WHILE x<>0 DO
BEGIN
x:=x-1;
OUTPUT(x^2.);
END
END
In the above example the two statements in the inner BEGIN
block are executed as long as x is not equal to zero. The inner
block will be executed five times and then the program will end.
37
REPEAT
Format: REPEAT <statements>
UNTIL <logical expression>;
The REPEAT statement is used to repeat execution of a set of
statements until a certain logical condition is true. The
difference between the REPEAT statement and the WHILE statement
is that the test is done after execution of the set of statements
with the REPEAT statement and before the set of statements with
the WHILE statement. An example.
BEGIN
REAL x;
x:=5;
REPEAT
x:=x-1;
OUTPUT(x^2.);
UNTIL x=0;
END
Note that there is no BEGIN block involved with the REPEAT
statement. The user may wish to take advantage of that aspect.
The statements between REPEAT and UNTIL will be executed five
times.
38
;
Format: ;
The empty statement is used as a place for a label. A GOTO
statement can then refer to this statement by its label if it is
labeled. An example.
BEGIN
STRING COMMAND;
INTEGER INP,OUTP;
COMMENT INP,OUTP ARE DECLARED AS INTEGERS AND ARE EXTERNAL
PROCEDURES;
LOOP:INPUT('ENTER A COMMAND:' @ COMMAND);
IF COMMAND = 'STOP' THEN GO FINISH;
IF COMMAND = 'INPUT' THEN CALL INP;
IF COMMAND = 'OUTPUT' THEN CALL OUTP;
GO LOOP;
FINISH:;
END
The above example has the empty statement with the label
FINISH. It is a point where the program will end when the
statement GO FINISH is executed. This is because the statement
after the empty statement is the final END statement.
39
DOS
Format: DOS;
The DOS statement causes program execution to return to the
MS DOS system. An example.
BEGIN
REAL I,J;
ask:OUTPUT('Enter upper limit:' @ J);
IF J<=0 THEN DOS;
FOR I:=1 STEP 1 UNTIL J DO
BEGIN
OUTPUT('The square root of ' @ I @ ' is ' @ SQR(I));
OUTPUT('The square of ' @ I ' is ' @ I*I );
END
GO ask;
END
The above example shows the DOS statement and it will be
executed,in this case,if the user enters a number less than or
equal to zero.
40
HOME
Format: HOME;
The HOME statement is used to clear the console screen and
place the cursor at the first column in the first row. An
example.
BEGIN
REAL x,y;
HOME;
FOR x:=.0 STEP .1 UNTIL 2*3.14159 DO
BEGIN
y:=SIN(x); PSET(101.*x,220.-101.*(y+1)),0;
END
busy:GO TO busy;
END
The above example uses HOME to clear the screen and then a
sine graph is plotted on the console screen.
41
DEFSEG
Format: DEFSEG := <expression>;
The DEFSEG statement is the same as the DEF SEG statement
but for the implementation of the Structured Programming Language
the name is one word. An example.
BEGIN
INTEGER A,H,C,D;
DEFSEG := 15.*4096.;
FOR A:=1 STEP 1 UNTIL 16*1024 DO
BEGIN
OUTPUT('Location:'@ A ,' Value:' @ PEEK(A));
END
END
The above example uses the DEFSEG statement to set the base
address for peeks and pokes to the sixteenth 64k segment.
42
EOT
Format: EOT
The EOT statement will have the Structured Programming
Language processor ask the user for a filename for additional
input. This allows the user to have multifile input of source
files to the processor. This allows for user source libraries of
Structured Programming Language procedures and declarations or
other Structured Programming Language source. The user can link
many source files together as long as the BEGIN and END
statements match and that the last END statement will cause the
second pass of the processor to run. It is recommended that the
EOT statement be placed on the last line of the source file by
itself and surrounded with a space on each side. An example.
BEGIN
REAL X,Y,Z;
INTEGER A,H,C;
EOT
This will cause the processor to ask for a new file name by
asking.
ENTER FILE NAME:
Then the user will enter the filename to be used. No
filename extension should be entered. Once the name is
entered, the processor will continue if the file is found. If the
file is not found,the processor will ask for another filename.
43
ARITHMETIC ASSIGNMENT STATEMENT
The Arithmetic assignment statement is used to assign values
by formula to INTEGER and REAL scalar and ARRAY variables defined
in a Structured Programming Language program. An example.
BEGIN
REAL PI,RADIUS,DIAMETER,HEIGHT;
REAL J,AREA,PERIMETER;
REAL ARRAY storage(26);
INTEGER i,k;
PI:=3.14159;
FOR i:=1 STEP 1 UNTIL 26 DO
BEGIN
storage(i):=0;
END
FOR J:=1. STEP .1 UNTIL 100. DO
BEGIN
DIAMETER:=J;
RADIUS:=DIAMETER/2.;
AREA:=PI*(RADIUS)^2.;
PERIMETER:=PI*DIAMETER;
OUTPUT(RADIUS,DIAMETER,AREA,PERIMETER);
END
END
The above example shows various arithmetic assignment
statements in the Structured Programming Language. Note the use
of the := as the assignment operator. The user must use this
form. The symbol = is used in logical expressions.
44
STRING ASSIGNMENT STATEMENT
The String assignment statement is used to assign string
values by formula to STRING scalar and ARRAY variables defined in
a Structured Programming Language program. An example.
BEGIN
STRING ARRAY names(50),phones(50);
STRING record,record1,record2;
INTEGER i;
INPUT(record1,record2);
record:=record1+MID$(record2,1,5); OUTPUT(record);
FOR i:=1 STEP 1 UNTIL 50 DO
BEGIN
INPUT(names(i),phones(i));
record:=names(i)+phones(i);
OUTPUT(record);
END
END
The above example shows various string assignment
statements. The := is the assignment operator. The = sign is used
in logical expressions.
45
LABELED STATEMENT
The labeled statement is any statement that has one or more
labels preceeding it. Some examples of isolated labeled
statements.
compute:X:=X+3.;
GONE:INPUT(x,y,z);
OUT1:putout:output: OUTPUT('Name','Address','Phone');
Finish:STOP;
A GO TO statement,RETURN <label>,RESUME <label> statement
can be used to transfer to a labeled statement. You may note the
use of the label, output. This name is not a keyword. OUTPUT is a
keyword, however.
46
ARITHMETIC OPERATORS
+ Addition
- Subtraction
/ Normal division
\ Integer division
MOD Modulo function
* Multiplication
^ Exponentiation
Refer to pages 5.19-5.26 in the ZBASIC users manual.
3-21 in the IBM BASICA users manual.
STRING OPERATORS
+ String concatenation
Concatenation of two or more strings means to join them together.
LOGICAL OPERATORS
AND Logical AND of two logical quantities.
OR Logical OR of two logical quantities.
NOT Logical NOT of a logical quantity.
XOR Logical exclusive OR of two logical quantities.
IMP Logical Implication of two logical quantities.
EQV Logical Equivalence of two logical quantities.
Refer to pages 5.32-5.45 in the ZBASIC manual.
3-25 in the IBM BASICA manual.
COMPARISON OPERATORS
= Equal to
< Less than
> Greater than
<= Less than or equal to
>= Greater than or equal to
<> Not equal to
Refer to pages 5.27-5.31 in the ZBASIC manual.
3-23 in the IBM BASICA manual.
47
IMPORTANT IMPLEMENTATION RESTRICTIONS AND CONVENTIONS
1. No more than 10 nested blocks may be set up in a Structured
Programming Language program. IF THEN ELSE statements,FOR
loops,WHILE statements,PROCEDUREs all create BEGIN blocks and
must be counted.
2. In Structured Programming Language programs, REAL floating
point constants with E or D are not supported. E.G. .245E5 or
.24556613D5 are illegal, however use .245 * 10^5 , .245566 *
10^5 instead.
3. However for INPUT the user must use the exponential format for
large numbers where the E format and D format are legal.
E.G. .245E5 and .245566D5 are legal input.
4. Arguments to PROCEDURE calls must either be a STRING ,INTEGER,
or REAL scalar variable, STRING constant, signed INTEGER constant
or fractional unsigned number less than one. The type of argument
must match the type of parameter. One exception is that the
numeric constant may be passed to a REAL or INTEGER parameter.
Expressions are not allowed. However arguments to EXTERNAL
PROCEDURES (FORTRAN,PASCAL,MACRO ASSEMBLER) can be any legal
expression. Consult your BASIC manual.
5. Variable names are allowed up to 40 characters,the first must
be alphabetic. Lower case characters are allowed.
6. All variables and PROCEDUREs except LABELS must be declared
before referencing them.
7. No Structured Programming Language reserved word may be used
as a variable name.
8. In Structured Programming Language statements that have either
arithmetic or string expressions, only some positional syntax
checking is done in the arithmetic expression. There is checking
to see if parentheses balance, if an illegal operator follows
another indicating that an operand is missing, if an operator or
punctuation is missing. Checking is done to see that variables
are declared and that operators and special characters are valid.
Reserved word usage is checked also.
9. No checks are made to see if the number of subscripts in a use
of an ARRAY variable match the number of bounds of that declared
ARRAY variable.
10. No checks are made to see if the number of arguments in a
PROCEDURE call match the number of parameters of that declared
PROCEDURE.
48
11. Concerning points 8 and 9,any errors not caught by the
Structured Programming Language processor, will surely be caught
by the BASIC interpreter in its run time system and surely by
your machine's BASIC compiler at compilation stage. The Symbol
table can be of great help in debugging a Structured Programming
Language program.
12. There is a limit of 250 variables that can be declared in a
BEGIN block. Variables can be declared in any BEGIN block, even
if it is a clause of THEN,ELSE,FOR loop,WHILE DO,PROCEDURE,etc.
13. String constants are limited to 250 characters although a
string variable can contain up to 32767 characters,if the
translated BASIC program is compiled.
14. All bounds that are declared in any ARRAY declaration must
be an integer constant. Variable bounds are not legal.
15. Declaration statements i.e. REAL,REAL ARRAY,INTEGER,INTEGER
ARRAY,STRING,STRING ARRAY,PROCEDURE must be placed before
executable statements in a BEGIN END block. An error will be
generated if you place a declaration after an executable
statement in that block.
16. PROCEDURE parameters if not declared are string variables.
They are considered as being declared in the BEGIN block that is
part of the PROCEDURE declaration. The parameter is only known in
that block or blocks nested in the PROCEDURE.
17. Labels are declared implicitly and are considered known in
every block in the program. They are considered as being declared
in the main program block, and therefore they are counted in the
total number of variables declared in the main program block.
REAL CONSTANTS
-1
-.433*10^5 Input form: -.433E5
INTEGER CONSTANTS
3200
-5
32767
STRING CONSTANTS
'ABC'
'This is a string'
'' ,the null string
Note:On entering a string for INPUT it must be between " double
quotes. Although if a string constant is the only constant
entered on INPUT or LINEIN then no " characters need to surround
the string. See your BASIC manual for entering string constants.
49
APPLICATION NOTES
1. All variables in a Structured Programming Language program
are put in COMMON in a certain order. If you wish to CHAIN
Structured Programming Language programs and use COMMON you
should declare the same variables from one module to another, and
they must be in the same order. It would help to use the same
declaration statements. If you don't declare the same variable
names, but you declare the same number of variables, and type of
variables or arrays with the same bounds, you may be able to use
the variables in COMMON. See your BASIC interpreter and/or
compiler manuals for details on COMMON. In addition, the same
procedures, if they use arguments must be declared in all CHAIN
modules. Again they should be in the same order in reference to
other variables.
2. You may wish to use double precision variables in your
program operations. To accomplish this you can modify the
translated BASIC program by placing a DEFDBL A statement before
any other statement in the program. This will change the
precision of all the REAL variables to double precision.
3. You will notice that the LOCATE, COLOR and SCREEN statements
are described in a format for the Zenith Z-100 machine. The
translator will understand those statements for your machine as
well,if you have an IBM PC or other machine. As long as you use
variables that conform to Structured Programming Language
standards, the statements will be translated properly. Of course
your BASIC compiler or interpreter will check for further
possibilities of syntax errors. For additional information you
should also check your machine's Basic language manual. (See
Implementation restrictions points 8 and 9)
50
RUNNING THE STRUCTURED PROGRAMMING LANGUAGE PROCESSOR
Make sure that your diskette contains the execute files
SP.EXE and SPA.EXE. These are the two files that make up the
Structured Programming Language processor. Place the disk with
the Structured Programming Language processor in the default disk
drive and enter SP. The processor will announce its name and ask
for a filename. If at this point you enter a letter followed by a
colon, the processor will display the [.SP] source files on that
disk drive. Enter a filename but not an extension. The processor
will add the extension .SP. All Structured Programming Language
programs must have a file extension .SP. It will ask the user
where scratch files and the final output file will be created. It
will ask if the user wants a symbol table, if the user wants a
listing, and if a listing is desired, then if the listing is to
go to the screen, disk or printer. This is for the first pass
only. If no listing is requested, all error messages will go to
the screen. The second pass messages go to the screen if the
listing is sent to the screen or to a disk file. If the listing
is sent to the printer, then the second pass messages go to the
printer as well. If you don't need a listing then the operation
of the translator is speeded up. The translator may be halted at
anytime during the first pass by pressing the space bar. When the
processor is done a program file <dev>:<filename>.BAS will reside
on the desired drive as an ascii file. This file MUST be loaded
into your BASIC interpreter workspace and SAVED IN THE ASCII
FORMAT,in order for compilation by your machine's BASIC compiler,
or the MICROSOFT BASIC Compiler.
SYMBOL TABLE AND SOURCE LISTING
The symbol table contains a dictionary which tells the user
information about each variable,label,procedure that is declared
in a Structured Programming Language program. The internal name
for a scalar variable is directly used in the translated BASIC
program. The internal names for ARRAY variables are the names
without the subscripts, labels are denoted as !, and PROCEDUREs
are shown as numbers, which is the exact number found for the
PROCEDURE in the translated BASIC program. The filename for the
optional symbol table file is <dev>:<filename>.SYM . The optional
source listing when directed to a disk file is in the file
<dev>:<filename>.LST. In the source listing, the Structured
Programming Language source code line number and the approximate
translated BASIC program line number appear before each
statement. This is supplied for debugging purposes.
LABEL FILE
A label file with the name <filename>.LBL is always created
and is used by the processor for creating a label dictionary. It
is retained so you can use it for debugging purposes. Since it
takes up disk space, you should consider that in operations of
the translator so as not to overflow disk space.
51
TRANSLATOR ERROR MESSAGES
Error messages generated are described in plain english and
go to the desired listing device. If no listing is desired then
the error messages go to the screen. A beep is sounded. The error
messages tell the user what line of the original source file the
error occurred, and the offending word is mentioned in the error
message. You will also find the footing *** ERROR IN LINE xxx
*** below the description. Since error messages are always
generated, and the line number is mentioned, it is a definite
speed advantage not to have a source listing generated. With many
editors you can call up a line by giving its line number and then
change it, so a source listing is not always needed.
Error Messages produced
by the Structured Programming Language Processor
------------------------------------------------------
Section 1 Fatal Internal Errors.
I1. IMPLEMENTATION RESTRICTION,INTERNAL NAME OVERFLOW
TRANSLATION TERMINATED
I2. INTERNAL STACK OVERFLOW,IMPLEMENTATION RESTRICTION: OOO
TRANSLATION TERMINATED.
I3. ERROR # XXX IN LINE NO. XXX {Contact author.}
{Line is in processor.}
Section 2 Auxilliary Error Messages.
M1. *** ERROR IN LINE XXX ***
M2. ERROR: WWW
Section 3 Main Error Messages.
1. MISSING OPERAND: WWW
2. UNBALANCED PARENTHESES
3. MISSING := : WWW
4. VARIABLE NOT DECLARED: WWW
5. VARIABLE IS NOT INTEGER,REAL,OR STRING: WWW
6. DECLARED VARIABLE PPP IS SCALAR,SUBSCRIPTED REFERENCE IS ILLEGAL
52
7. DECLARED VARIABLE PPP
IS AN ARRAY, MISSING LEFT PARENTHESIS,COMMA,OR SEMICOLON
8. MISSING OPERATOR OR PUNCTUATION FOLLOWING AN IDENTIFIER OR
CONSTANT : PPP
9. MISSING BEGIN STATEMENT: WWW
FATAL ERROR,TRANSLATION STOPPED
10. ILLEGAL VARIABLE NAME: WWW
11. ILLEGAL PROCEDURE NAME: WWW
12. MISSING (
13. MISSING DIMENSION: WWW
14. MISSING ) OR , : WWW
15. MISSING , OR ; : WWW
16. ILLEGAL OR MISSING PARAMETER: WWW
17. MISSING ; : WWW
18. ILLEGAL PROCEDURE: WWW
19. MISSING ( : WWW
20. INVALID INPUT LIST: WWW
21. MISSING ) : WWW
22. INVALID OUTPUT LIST: WWW
23. ILLEGAL LOOP VARIABLE: WWW
24. ILLEGAL EXPRESSION: WWW
25. DUPLICATE LABEL: WWW
26. ILLEGAL STATEMENT TYPE: WWW
27. UNDECLARED VARIABLE NAME, OR MISSING COLON : WWW
28. IN THIS INSTANCE WWW STATEMENT MUST BE ENCLOSED WITHIN
A BEGIN END BLOCK,ERROR
29. END STATEMENT IS NOT A LEGAL STATEMENT HERE
30. TOO MANY NESTED BEGIN BLOCKS
TRANSLATION TERMINATED
31. DUPLICATE PROCEDURE NAME: WWW
53
32. OVERFLOW OF SYMBOL TABLE: WWW
33. ATTEMPT TO NEST 11TH LEVEL TRANSLATION TERMINATED
34. DUPLICATE PARAMETER: WWW
35. LIMIT OF 10 PARAMETERS EXCEEDED: WWW
36. DUPLICATE VARIABLE: WWW
37. DUPLICATE ARRAY NAME: WWW
38. SYMBOL TABLE OVERFLOW,TOO MANY VARIABLES: WWW
39. ILLEGAL LABEL: WWW
40. MISSING ; OR ( : WWW
41. ILLEGAL ARGUMENT: WWW
42. MISSING , OR ) : WWW
43. MISSING WORD,STEP : WWW
44. MISSING WORD,UNTIL: WWW
45. MISSING WORD,DO: WWW
46. MISSING WORD,THEN: WWW
47. ERROR,LAST WORD NOT END OR EOT : WWW
48. ERROR,UNTIL WITHOUT REPEAT CLAUSE
49. ILLEGAL USE OF RESERVED WORD
AS STATEMENT,VARIABLE,OR LABEL: WWW
50. ELSE CLAUSE NOT EXPECTED,ERROR
51. ILLEGAL PLACEMENT OF A DECLARATION STATEMENT: WWW
52. MISSING WORD,CALL: WWW
53. WORD IS NOT KEY OR COM: WWW
54. DOUBLE QUOTE ILLEGAL,REPLACED WITH SPACE,USE CHR$(34)
*** ERROR IN LINE XXX ***
54
Legend: XXX Line number.
WWW Offending word in source program.
PPP Word previous to one that caused error.
OOO Line that overflowed internal stack.
55
INDEX of Statements for the Structured Programming Language.
The numbers refer to pages in this manual except in the case
where a Z or an I preceeds it.
; 39
Arithmetic assignment 44
BEEP *Z 10.5 *I 4-28
BEGIN 14
BLOAD **Z 10.6-10.7 **I 4-29
BSAVE **Z 10.8-10.9 **I 4-32
CALL 33
CALL [EXTERNAL] *Z 10.10-10.11 *I 4-34
CHAIN **Z 10.13-10.14 **I 4-36
CIRCLE *Z 10.17 *I 4-41
CLEAR *Z 10.18 *I 4-44
CLOSE **Z 10.19 **I 4-46
COLOR *Z 10.21-10.22 *I 4-49,4-54
COM(N) *Z F.8-F.10 *I 4-56
COMMENT 25
DATE$ *Z 10.32 *I 4-66
DEFSEG 42
DOS 40
DRAW *Z 10.40-10.41 *I 4-79
END 36
EOT 43
ERROR *Z 10.47-10.48 *I 4-91
FIELD *Z 10.50 *I 4-94
FILES **Z 10.51 **I 4-97
FOR 34
GET [GRAPHICS] *Z 10.59-10.61 *I 4-108
GET [I/O] 31
GO 26
GO TO 26
GOTO 26
HOME 41
IF 35
INPUT 29
INTEGER 18
INTEGER ARRAY 21
KEY *Z 10.81-10.83 *I 4-131
KEY(N) *Z F.8-F.10 *I 4-134
KILL **Z 10.84 **I 4-136
Labeled statement 46
LINE *Z 10.88-10.89 *I 4-141
LINEIN 30
LOCATE *Z 10.97-10.98 *I 4-155
LSET *Z 10.103 *I 4-163
MID$ *Z 10.106 *I 4-167
NAME **Z 10.108 **I 4-173
NULL *Z 10.110
ON COM(N) *Z F.8-F.10 *I 4-176
ON KEY(N) *Z F.8-F.10 *I 4-182
ONERRGOTO 27
56
OPEN **Z 10.115-10.121 **I 4-189,4-194
OUT **Z 10.123 **I 4-201
OUTPUT 32
PAINT *Z 10.124 *I 4-203
POKE *Z 10.127 *I 4-214
PRESET *Z 10.129 *I 4-228
PROCEDURE 23
PSET *Z 10.138-10.139 *I 4-228
PUT [GRAPHICS] *Z 10.59-10.61 *I 4-232
PUT [I/O] 31
RANDOMIZE *Z 10.141 *I 4-236
REAL 16
REAL ARRAY 20
REPEAT 38
RESET *Z 10.146 *I 4-243
RESUME *Z 10.148 *I 4-245
RETURN 28
RSET *Z 10.103 *I 4-163
RUN **Z 10.152 **I 4-251
SCREEN *Z 10.155 *I 4-257
STOP *Z 10.161 *I 4-270
STRING 19
STRING ARRAY 22
String assignment 45
SWAP *Z 10.164 *I 4-277
TIME$ *Z 10.168-10.169 *I 4-281
WAIT *Z 10.176 *I 4-290
WHILE 37
WIDTH *Z 10.178 *I 4-294
WRITE *Z 10.179-10.180 *I 4-298 4-299
57